package vcp.server.requesthandler;

import ocsf.server.ConnectionToClient;
import vcp.client.request.SiteCostUpdateRequest;
import vcp.client.request.response.ResponseRequest;
import vcp.entity.SiteCostUpdates;
import vcp.enums.SiteEnum.SiteCostsUpdateStatus;
import vcp.server.DAO.SiteCostUpdatesDAO;
import vcp.server.interfaces.IServer;
import vcp.server.utility.Constants.TableNames;
/**
 * 
 * @author VCP team
 *<p>
 *class handles request from client and updates a cost update request
 *</p>
 */
public class SiteCostUpdateRequestHandler extends RequestHandler <SiteCostUpdateRequest>
{
	/**
	 * class constructor
	 * @param server
	 */
	public SiteCostUpdateRequestHandler ( IServer server )
	{
		super(server);
	}

	@Override
	public void execute ( SiteCostUpdateRequest request, ConnectionToClient client )
	{
		SiteCostUpdatesDAO siteCostUpdatesDAO = new SiteCostUpdatesDAO();
		SiteCostUpdates siteCostUpdates = new SiteCostUpdates();

		siteCostUpdates.setID(this.server.getGeneratedID(TableNames.SITE_COSTS_UPDATE));
		siteCostUpdates.setSiteEnum(request.getSiteCostUpdateForm().getRequestedSite());
		siteCostUpdates.setSingleUsePricePerHour(request.getSiteCostUpdateForm().getSingleUsePricePerHour());
		siteCostUpdates.setOrderAheadPricePerHour(request.getSiteCostUpdateForm().getOrderAheadPricePerHour());
		siteCostUpdates.setCasualPriceSingleCar(request.getSiteCostUpdateForm().getCasualPriceSingleCar());
		siteCostUpdates.setFullPriceSingleCar(request.getSiteCostUpdateForm().getFullPriceSingleCar());
		siteCostUpdates.setStatus(SiteCostsUpdateStatus.PENDING);

		siteCostUpdatesDAO.save(siteCostUpdates);

		this.sendResponseRefresh(siteCostUpdates, client);
		this.sendResponse(new ResponseRequest(request.getRequestID(), siteCostUpdates), client);
	}

}
